<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <form name="form">
      <p>
        <input type="text" name="input" />
      </p>
    </form>
    <script>
      document.form.input.onfocus = function () {
        console.log("onfocus");
      };

      document.form.input.onblur = function () {
        console.log("onblur");
      };
      setTimeout(() => {
        // 获取焦点触发获取焦点事件
        document.form.input.focus();
      }, 3000);

      setTimeout(() => {
        // 取消焦点触发失去焦点事件
        document.form.input.blur();
      }, 6000);
    </script>
  </body>
</html>
